frames = []
for stock_index in etf50_id:
    print(stock_index)
    tmp_df = etf50[stock_index]
    holding_cash = (
        1000
        * tmp_df.groupby(pd.DatetimeIndex(tmp_df.index).to_period("M"))
        .nth(0)["Close"]
        .sum()
    )
    test = Backtest(
        etf50[stock_index],
        ContinueHolding,
        cash=holding_cash,
        commission=0.004,
        # exclusive_orders=True,
        trade_on_close=True,
    )
    result = test.run()
    result["stock_id"] = stock_index
    result["Cash"] = holding_cash
    result["Strategy"] = result["_strategy"].__class__.__name__
    result["Params"] = result["_strategy"].params
    df = result.to_frame().transpose()
    frames.append(df)
本金 = Sum( 每月交易日首日收盤價 * 1000 )
tmp_df = etf50[stock_index]
holding_cash = (
    1000
    * tmp_df.groupby(pd.DatetimeIndex(tmp_df.index).to_period("M"))
    .nth(0)["Close"]
    .sum()
)
test = Backtest(
    etf50[stock_index],
    ContinueHolding,
    cash=holding_cash,
    commission=0.004,
    # exclusive_orders=False,
    trade_on_close=True,
)
result = test.run()
final_df = pd.concat(frames).reset_index(drop=True)
final_df = final_df.loc[
    final_df["Duration"] == final_df["Duration"].max()
].reset_index(drop=True)
etf50_df = final_df.loc[final_df["stock_id"] == "0050", "Return (Ann.) [%]"]
profit_df = final_df[final_df["Return (Ann.) [%]"] >= etf50_df[0]]
由報表可以看出,以平均來說「只買不賣」策略低的可憐,
年化報酬率只有可憐的0.73%(甚至比定存還低),
而所有成分股中超過ETF50投資報酬率的只有13個,
我們可以將其當成日後其他策略的參考線,
只要年化報酬率低於**「只買不賣」策略或ETF50**的年化報酬率,
即可視為「糟糕」的策略。
股票ID	|股票名稱|	年化報酬率 [%]|	夏普率|	系統質量(SQN)
------------- | -------------
TW  |	台股平均|	0.73529|	|	
0050|	元大台灣50	|1.75358|	0.206715	|7.19137|
2330|	台積電		|5.78504|	0.431027	|12.2543|
1301|	台塑		|2.30122|	0.199212	|11.2324|
1216|	統一		|2.7866|		0.210213	|13.1493|
3008|	大立光		|2.62141|	0.0995397	|3.0121 |
5871|	中租-KY		|4.62837|	0.291684	|13.0569|
1326|	台化		|2.85479|	0.218428	|11.1298|
2379|	瑞昱		|6.71893|	0.319554	|20.2988|
2327|	國巨		|14.9039|	0.389574	|8.04219|
2912|	統一超		|4.59893|	0.30617		|15.5105|
6505|	台塑化		|2.69953|	0.173866	|9.66391|
1590|	亞德客-KY	|2.39312|	0.0805668	|3.92964|
9910|	豐泰		|7.19998|	0.319489	|11.4869|
2408|	南亞科		|5.61503|	0.151951	|5.1359 |